package org.tc.feign.client.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tc.client.entity.Collections;
import org.tc.feign.client.service.FeignCollectionService;

import java.util.List;

@CrossOrigin(origins = {"*"},methods={RequestMethod.GET,RequestMethod.POST,RequestMethod.OPTIONS})

@RestController
public class FeignCollectionController {

    @Autowired
    private FeignCollectionService collectionsService;


    /**
     * 收藏商品
     * @param collection
     * @return
     */
    @RequestMapping("/insertCollections")
    public int insert(@RequestBody Collections collection)
    {
        System.out.println("收藏商品");
        return collectionsService.insert(collection);
    }

    /**
     * 根据id删除收藏的商品
     * @param id
     * @return
     */
    @RequestMapping("/deleteCollectionById")
    public int deleteCollectionById(@RequestParam("id") Integer id){
        System.out.println("删除收藏商品");
        return collectionsService.deleteById(id);
    }

    /**
     * 查看用户的收藏商品
     * @param userid
     * @return
     */
    @RequestMapping("/selectCollByuserId")
    public List<Collections> selectCollByuserId(Integer userid){
        System.out.println("用户"+userid+"收藏的商品");
        return collectionsService.selectCollByUserId(userid);
    }

}
